package com.example.dllo.baidumusic.adapter;
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         佛祖保佑       永无BUG
*/

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.example.dllo.baidumusic.R;
import com.example.dllo.baidumusic.bean.HotSingBean;
import com.example.dllo.baidumusic.bean.MusicBean;
import com.example.dllo.baidumusic.nettool.URLValuas;
import com.example.dllo.baidumusic.nettool.NetTool;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by dllo on 16/8/19.
 */
public class PaiHangSingAdapter extends BaseAdapter {
    private HotSingBean hotSingBean;
    Context mContext;

    public PaiHangSingAdapter(Context mContext) {
        this.mContext = mContext;
    }

    public void setHotSingBean(HotSingBean hotSingBean) {
        this.hotSingBean = hotSingBean;
    }

    public List<MusicBean> getMusicList() {
        List<MusicBean> musicBeanList = new ArrayList<>();
        for (HotSingBean.SongListBean songListBean : hotSingBean.getSong_list()) {
            MusicBean musicBean = new MusicBean();
            musicBean.setUrl(URLValuas.PLAY_FRONT + songListBean.getSong_id() + URLValuas.PLAY_BEHIND);
            //TODO 其他信息
            musicBeanList.add(musicBean);
        }
        return musicBeanList;
    }

    @Override
    public int getCount() {
        return hotSingBean == null ? 0 : hotSingBean.getSong_list().size();
    }

    @Override
    public Object getItem(int position) {
        return position;
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        ViewHoler viewHoler = null;
        if (convertView == null) {
            convertView = LayoutInflater.from(mContext).inflate(R.layout.item_hotsing, parent, false);
            viewHoler = new ViewHoler(convertView);
            convertView.setTag(viewHoler);
        } else {
            viewHoler = (ViewHoler) convertView.getTag();
        }


        viewHoler.title.setText(hotSingBean.getSong_list().get(position).getTitle());
        viewHoler.author.setText(hotSingBean.getSong_list().get(position).getAuthor());
        NetTool netTool = new NetTool();
        netTool.getImage(hotSingBean.getSong_list().get(position).getPic_big(), viewHoler.img);


        return convertView;
    }

    public class ViewHoler {
        ImageView img;
        TextView title;
        TextView author;

        public ViewHoler(View convertView) {

            img = (ImageView) convertView.findViewById(R.id.item_hotsing_img);
            title = (TextView) convertView.findViewById(R.id.item_hotsing_singname);
            author = (TextView) convertView.findViewById(R.id.item_hotsing_author);


        }
    }
}
